// router/index.js  
import { createRouter, createWebHashHistory } from 'vue-router';  
import { useRouterStore } from '../store/router'
import componentMap from './componentMap'


const Home =() => import('../pages/Home/index.vue')
const Login =() => import('../pages/Login/index.vue')
const  Error=() => import('../pages/Error/index.vue')

const staticRoutes = [  
  { path: '/login', component:Login  },  
  { path: '/', name:'Home',redirect:'/home' ,children:[] } ,
  {path:'/404',component:Error}
];  

const router = createRouter({  
  history: createWebHashHistory(),  
  routes: staticRoutes  
});  

// 动态加载路由函数  
export const setupDynamicRoutes = async () => {  
  const {dynamicRoutes} = useRouterStore();
console.log(dynamicRoutes);
  if (dynamicRoutes) {  
    dynamicRoutes.forEach(route => {  
     route.component=componentMap[route.component]
      router.addRoute('Home',route)
    });  
  }  
  router.addRoute({ path: '/:pathMatch(.*)*', redirect: '/404' });
  console.log(router.getRoutes());
  
};  
export default router